package com.qen.dynamictable;

import org.beetl.core.fun.MethodInvoker;
import org.beetl.core.fun.ObjectUtil;

import java.io.Serializable;

/**
 * @author licz
 * @title BaseEntity
 * @date 2025/1/8 11:05
 * @description 动态表的基类，因beetsql 提供的没有实现Serializable,兼容老版本
 */
public abstract class BaseEntityExt  implements Serializable {

    public void setValue(String attrName, Object value) {
        MethodInvoker methodInvoker = ObjectUtil.getInvokder(this.getClass(), attrName);
        if (methodInvoker == null) {
            throw new IllegalArgumentException("不存在的属性 " + attrName);
        } else {
            methodInvoker.set(this, value);
        }
    }

    public Object getValue(String attrName) {
        MethodInvoker methodInvoker = ObjectUtil.getInvokder(this.getClass(), attrName);
        if (methodInvoker == null) {
            throw new IllegalArgumentException("不存在的属性 " + attrName);
        } else {
            return methodInvoker.get(this);
        }
    }
}